package com.ybb.account.service;

import com.ybb.account.mapper.UserAccountChangeMapper;
import com.ybb.account.mapper.UserAccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserAccountServiceImpl implements UserAccountService {


    @Autowired
    private UserAccountMapper userAccountMapper;
    @Autowired
    private UserAccountChangeMapper userAccountChangeMapper;

    public void enchargeAccount(String userCode, Double amount) {
        getUserAccountBalanceInLock(userCode);//先锁定客户
        //记录用户账户变化
        userAccountChangeMapper.insertChange(userCode, amount);
        //变更用户账户
        userAccountMapper.changeAccount(userCode, amount);
    }

    public Double getUserAccountBalanceInLock(String userCode) {
        return userAccountMapper.getUserAccountBalanceInLock(userCode);
    }
}
